package com.gwclh.personnel.controller;


import cn.hutool.core.lang.Assert;
import com.gwclh.personnel.bean.ResultVo;
import com.gwclh.personnel.domain.PageDomain;
import com.gwclh.personnel.entity.DeptTransfer;
import com.gwclh.personnel.service.IDeptTransferService;
import com.gwclh.personnel.utils.ShiroUtil;
import com.gwclh.personnel.vo.transfervo.DeptTransFerVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 部门调动记录表 前端控制器
 * </p>
 *
 * @author gzhhh
 * @since 2020-07-24
 */
@RestController
@RequestMapping("/dept-transfer")
@Api(value = "部门调转表")
public class DeptTransferController extends BaseController {

    @Autowired
    IDeptTransferService deptTransferService;

    @GetMapping("")
    @ApiOperation(value = "分页展示部门调转记录")
    public ResultVo listDeptTrans(DeptTransFerVo deptTransFerVo, HttpServletRequest request) {
        PageDomain pageDomain = getPageParams(request);
        return deptTransferService.listTrans(pageDomain, deptTransFerVo);
    }

    @PostMapping("")
    @ApiOperation(value = "添加部门调转记录")
    public ResultVo addDeptTran(@Validated @RequestBody DeptTransfer deptTransfer) {

        return deptTransferService.addTrans(deptTransfer);
    }


    @GetMapping("/data/{pId}")
    public ResultVo getData(@PathVariable(value = "pId") Integer pId) {
        return ResultVo.success(deptTransferService.getDeptTransData(pId));
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除部门调转记录")
    public ResultVo delDeptTransLog(@PathVariable Integer id){
        Assert.isTrue(deptTransferService.removeById(id),"删除调转记录失败");
        deptTransferService.removeById(id);
        return ResultVo.success();
    }
}
